package cn.yuanqiao.web.controller.archive.appManager;

import cn.yuanqiao.archive.appManager.domain.TenantCodeRule;
import cn.yuanqiao.archive.appManager.service.ITenantCoderuleService;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;

/**
 * manageController
 * 
 * @author yuanqiao
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/archive/coderule")
public class TenantCoderuleController extends BaseController
{
    @Autowired
    private ITenantCoderuleService tenantCoderuleService;

    /**
     * 查询档号规则列表
     * @author syd
     * @param yqdaCoderuleModel
     * @return
     */
    //@RequiresPermissionssions("archive:coderule:list")
    @GetMapping("/list")
    @Log(title = "查询档号规则列表", businessType = BusinessType.SELECT)
    public TableDataInfo list(TenantCodeRule yqdaCoderuleModel)
    {
        startPage();
        List<TenantCodeRule> list = tenantCoderuleService.selectYqdaCoderuleModelList(yqdaCoderuleModel);
        return getDataTable(list);
    }

    /**
     * 导出manage列表
     */
    //@RequiresPermissionssions("archive:coderule:export")
    @Log(title = "manage", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantCodeRule yqdaCoderuleModel)
    {
        List<TenantCodeRule> list = tenantCoderuleService.selectYqdaCoderuleModelList(yqdaCoderuleModel);
        ExcelUtil<TenantCodeRule> util = new ExcelUtil<TenantCodeRule>(TenantCodeRule.class);
        util.exportExcel(response, list, "manage数据");
    }

    /**
     * 获取manage详细信息
     */
    //@RequiresPermissionssions("archive:coderule:query")
    @GetMapping(value = "/{Id}")
    //@Log(title = "查询档号规则信息", businessType = BusinessType.SELECT)
    public AjaxResult getInfo(@PathVariable("Id") Long Id)
    {
        return success(tenantCoderuleService.selectYqdaCoderuleModelById(Id));
    }

    /**
     * 新增档号规则
     * @author syd
     * @param yqdaCoderuleModel
     * @return
     * @throws ParseException
     */
    //@RequiresPermissionssions("archive:coderule:add")
    @Log(title = "新增档号规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TenantCodeRule yqdaCoderuleModel) throws ParseException {
        String result=tenantCoderuleService.insertYqdaCoderuleModel(yqdaCoderuleModel);
        if("ok".equals(result)){
            return AjaxResult.success();
        }else{
            return AjaxResult.error(result);
        }
    }

    /**
     * 修改档号规则
     * @author syd
     * @param yqdaCoderuleModel
     * @return
     * @throws ParseException
     */
    //@RequiresPermissionssions("archive:coderule:edit")
    @Log(title = "修改档号规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TenantCodeRule yqdaCoderuleModel) throws ParseException {
        String result=tenantCoderuleService.updateYqdaCoderuleModel(yqdaCoderuleModel);
        if("ok".equals(result)){
            return AjaxResult.success();
        }else{
            return AjaxResult.error(result);
        }
    }

    /**
     * 删除档号规则
     * @author syd
     * @param Ids
     * @return
     */
    //@RequiresPermissionssions("archive:coderule:remove")
    @Log(title = "删除档号规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids)
    {
        return toAjax(tenantCoderuleService.deleteYqdaCoderuleModelByIds(Ids));
    }
}
